// 写一个基于typeScript设计模式的迭代器模式
type Iterator<T> = {
    current: () => T,
    next: () => T,
    hasNext: () => boolean,
}
type List<T> = {
    data: T[],
    iterator: () => Iterator<T>
}
const list: List<number> = {
    data: [1, 2, 3, 4, 5],
    iterator() {
        let index = 0
        return {
            current() {
                return list.data[index]
            },
            next() {
                return list.data[index++]
            },
            hasNext() {
                return index < list.data.length
            }
        }
    }
}
const iterator = list.iterator()
while (iterator.hasNext()) {
    console.log(iterator.next())
}